package com.twu.biblioteca.model.menu.actions;


import com.twu.biblioteca.model.LibraryItem;
import com.twu.biblioteca.model.menu.Menu;
import com.twu.biblioteca.model.menu.MenuAction;

public class ReturnAction extends MenuAction {

    private final Class itemType;

    public ReturnAction(boolean needsLogin, Class itemType) {
        super(needsLogin);
        this.itemType = itemType;
    }

    @Override
    public boolean performAction(Menu menu, String[] args) {
        for (LibraryItem item : menu.getLoggedInCustomer().getCheckedOutItems()) {
            if (item.getClass() == itemType && item.hasDetails(args)) {
                item.setCheckedOut(false);
                menu.getLoggedInCustomer().getCheckedOutItems().remove(item);
                return true;
            }
        }
        return false;
    }
}
